home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-01-14 | 6.3 KB | 229 lines | [TEXT/KAHL] |
- /******************************************************************************
- CNeoPopupPane.c
-
- A subclass of CStdPopupMenu that support multiple font sizes.
-
- SUPERCLASS = CStdPopupMenuPane
-
- Copyright © 1992 NeoLogic Systems. All rights reserved.
-
-
- ******************************************************************************/
-
- #include "NeoTypes.h"
- #include "CBartender.h"
- #include "CPaneBorder.h"
- #include "CPopupMenu.h"
- #include "CNeoPopupPane.h"
- #include "CNeoDemoDoc.h"
- #include "CNeoDLOGDialog.h"
-
- #define SysFontFam ((short*) 0x0BA6)
- #define SysFontSize ((short*) 0x0BA8)
- #define LastSpExtra ((long*) 0x0B4C)
-
- extern CBartender *gBartender;
-
- /******************************************************************************
- CNeoPopupPane
-
- Create a standard popup menu pane. The constant kAutoSize may be passed
- for both aWidth and aHeight to request that the popup dimensions
- be calculated to the best size.
- ******************************************************************************/
-
- void CNeoPopupPane::INeoPopupPane(short menuID, CView *anEnclosure,
- CBureaucrat *aSupervisor, short aWidth, short aHeight,
- short aHEncl, short aVEncl, short aTitleGap)
- {
- fTitleGap = aTitleGap;
- fCurrentItem = 1;
- IStdPopupPane(menuID, anEnclosure, aSupervisor, aWidth, aHeight, aHEncl, aVEncl);
- } /* CNeoPopupPane::INeoPopupPane */
-
- /******************************************************************************
- CalcDimensions
-
- Calculate dimensions and location constants needed to properly draw the
- popup.
- ******************************************************************************/
-
- void CNeoPopupPane::CalcDimensions()
- {
- short newWidth, newHeight;
- Rect deltaSize;
- Str255 title;
- FontInfo fInfo;
-
- Prepare();
- itsMenu->GetTitle(title);
- titleWidth = StringWidth(title);
- GetFontInfo(&fInfo);
-
- /* fontAscent is used when drawing the popup title and selected item */
- fontAscent = fInfo.ascent +1;
-
- if (width == kAutoSize)
- {
- /* calculte width such that title, the longest menu item, and */
- /* the down arrow all fit correctly */
-
- newWidth = titleWidth + fTitleGap + itsMenu->GetWidth(); /* TCL 1.1.1 DLP 9/18/91 */
- }
- else newWidth = width;
-
- if (height == kAutoSize)
- {
- /* calculate the height given the chosen font, but make sure */
- /* the height is at least an appropriate minimum size */
-
- newHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
- newHeight = Max(kStdPopupHeight, newHeight);
- }
- else newHeight = height;
-
- SetRect(&deltaSize, 0, 0, newWidth - width, newHeight - height);
- ChangeSize(&deltaSize, FALSE);
-
- /* calculate the rect to hilite when the menu pops up, as per HIG */
-
- SetRect(&hiliteRect, 0, 1, titleWidth + fTitleGap,
- fInfo.ascent + fInfo.descent + fInfo.leading + 1);
-
- /* calculate the position to draw the down arrow SICN */
-
- sicnPt.h = width - kArrowWidth - kBorderWidth - kArrowRightInset;
- sicnPt.v = 4;
-
- } /* CNeoPopupPane::CalcDimensions */
-
- /******************************************************************************
- DoClick {OVERRIDE}
-
- Hancle a click in the popup. As per HIG, we only popup the menu
- when the popup box is clicked, not just any part of the pane.
- We also hilite the title while the menu is popped up.
- ******************************************************************************/
-
- void CNeoPopupPane::DoClick( Point hitPt, short modifierKeys, long when)
- {
- short saveFont;
- short saveSize;
- short count;
- short index;
- MenuHandle menu;
-
-
- saveFont = textFont;
- textFont = 0;
- *LastSpExtra = -1L; // Signal to flush font cache
-
- count = itsMenu->GetNumItems();
- menu = itsMenu->GetMacMenu();
- for (index = 1; index <= count; index++)
- SetItemMark(menu, index, ((index == fCurrentItem) ? checkMark : noMark));
-
- inherited::DoClick(hitPt, modifierKeys, when);
-
- fCurrentItem = itsMenu->GetCheckedItem();
- textFont = saveFont;
- *LastSpExtra = -1L; // Signal to flush font cache
- } /* CNeoPopupPane::DoClick */
-
- /******************************************************************************
- GetCheckedItem
-
- Return item number if any item in menu has a checkmark, else
- returns 0.
- ******************************************************************************/
-
- short CNeoPopupPane::GetCheckedItem(void)
- {
- return fCurrentItem;
- } /* CNeoPopupPane::GetCheckedItem */
-
- /******************************************************************************
- MakePopupBox
-
- Create the pane and border used to draw the popup box and drop shadow
- ******************************************************************************/
-
- void CNeoPopupPane::MakePopupBox(void)
- {
- CPaneBorder *border;
- short bWidth;
-
- bWidth = width - titleWidth - fTitleGap-2;
-
- popupPt.h = titleWidth + fTitleGap;
- popupPt.v = 1;
-
- itsPopupBox = new(CPane);
- itsPopupBox->IPane(this, this, bWidth, height-kBorderWidth-1, popupPt.h,
- 1, sizFIXEDSTICKY, sizFIXEDSTICKY);
-
- border = new(CPaneBorder);
- border->IPaneBorder(kBorderFrame);
- border->SetShadow(2, 2, 1, 1);
-
- itsPopupBox->SetBorder(border);
-
- } /* CStdPopupPane::MakePopupBox */
-
- /******************************************************************************
- ProviderChanged
-
- Create the pane and border used to draw the popup box and drop shadow
- ******************************************************************************/
-
- void CNeoPopupPane::ProviderChanged(CCollaborator *aProvider, long aReason, void* aParam)
- {
- switch (aReason) {
- case popupMenuNewSelection:
- if (aProvider == itsMenu) {
- ((CNeoDemoDoc *)((CNeoDLOGDialog *)itsSupervisor)->itsSupervisor)->setImageDirty(this, aParam, TRUE);
- Refresh();
- }
- break;
- }
-
- inherited::ProviderChanged(aProvider, aReason, aParam);
- }
-
- /******************************************************************************
- SelectItem
-
- Applys the action requested in actionType to the item. The valid
- actions are:
- pmForceOn - always check the item
- pmForceOff - always uncheck the item
- pmToggle - check if unchecked, uncheck if checked.
- ******************************************************************************/
-
- void CNeoPopupPane::SelectItem(short aItem, tPMSelectAction aType)
- {
- itsMenu->SelectItem(aItem, aType);
-
- switch (aType) {
- case pmToggle:
- if (aItem == fCurrentItem)
- fCurrentItem = 0;
- else
- NeoAssert(FALSE);
- break;
-
- case pmForceOn:
- fCurrentItem = aItem;
- break;
-
- case pmForceOff:
- if (aItem == fCurrentItem)
- NeoAssert(FALSE);
- else
- fCurrentItem = 0;
- break;
- }
- } /* CNeoPopupPane::SelectItem */
-
-
-